package dao;

import org.example.bean.EmpInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

@Repository
public class EmpInfoDAO {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    public List<EmpInfo> findAllEmp(){
        String sql = "select * from emp where empstate=1";
        List<EmpInfo> list = jdbcTemplate.query(sql,new MyRowMapper());
        return list;
    }

    class MyRowMapper implements RowMapper<EmpInfo> {
        @Override
        public EmpInfo mapRow(ResultSet rs, int i) throws SQLException {
            EmpInfo ei = new EmpInfo();
            ei.setEmpNo(rs.getInt(1));
            ei.setEname(rs.getString(2));
            ei.setJob(rs.getString(3));
            ei.setMgr(rs.getInt(4));
            ei.setHireDate(rs.getString(5));
            ei.setSal(rs.getDouble(6));
            ei.setComm(rs.getDouble(7));
            ei.setDeptNo(rs.getInt(8));
            ei.setEmpState(rs.getInt(9));
            return ei;
        }
    }
}
